package gui;

import dados.BancoQuestoes;
import dados.Estado;

import dados.Questao;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import dados.QuestaoProva;
import java.awt.event.WindowListener;
import java.io.File;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.UIManager;
import logica.GerenciaBanco;
import logica.GerenciaSerializacao;

/**
 *
 * @author  Yuri Maia
 */
public class JanelaProva extends javax.swing.JDialog {
    
    private boolean modificado = false;
    private ArrayList<QuestaoProva> bancoQuestoes = null;
    private ArrayList<QuestaoProva> estadoInicial = null;
    /** Creates new form Entradas */
    public JanelaProva(javax.swing.JDialog pai) {
        super(pai, "Banco de Quest�es", true);
        initComponents();
        bancoQuestoes = new ArrayList();
        estadoInicial = new ArrayList();
        estadoInicial.addAll(bancoQuestoes);
        Janelas.alinharContainer(this);
        txtEnunciado.setEditable(false);
        btnAdicionarQuestao.setEnabled(true);
        btnRemoverQuestao.setEnabled(false);
        btnAdicionarVersao.setEnabled(false);
        btnRemoverVersao.setEnabled(false);
        inicializarJOptionPane();
        this.addKeyListener(new KeyListenerJanela());
        this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        this.addWindowListener(new WindowListener() {

            public void windowOpened(WindowEvent e) {

            }

            public void windowClosing(WindowEvent e) {
                if(modificado){
                    int opcao = JOptionPane.showConfirmDialog(null, "Existem alterações não salvas. Deseja sair assim mesmo?", "Atenção!", JOptionPane.OK_CANCEL_OPTION);
                    if(opcao == JOptionPane.OK_OPTION)
                        dispose();
                    
                } else {
                    dispose();
                }
            }

            public void windowClosed(WindowEvent e) {

            }

            public void windowIconified(WindowEvent e) {

            }

            public void windowDeiconified(WindowEvent e) {

            }

            public void windowActivated(WindowEvent e) {

            }

            public void windowDeactivated(WindowEvent e) {

            }
        });
    }
    
    public JanelaProva(javax.swing.JDialog pai, ArrayList<QuestaoProva> provas) {
        super(pai, "Banco de Quest�es", true);
        initComponents();
        bancoQuestoes = provas;
        estadoInicial = new ArrayList();
        estadoInicial.addAll(bancoQuestoes);
        txtEnunciado.setEditable(false);
        iniciarListas();
        Janelas.alinharContainer(this);
        this.addKeyListener(new KeyListenerJanela());
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    
    private void inicializarJOptionPane() {
        UIManager.put("OptionPane.cancelButtonText", "Cancelar");
    }
    
    private void iniciarListas() {
        
        btnRemoverQuestao.setEnabled(false);
        btnAdicionarVersao.setEnabled(false);
        btnRemoverVersao.setEnabled(false);
        txtEnunciado.setText("");
        listaQuestoes.setListData(new String[0]);
        listaVersoes.setListData(new String[0]);
        if (!bancoQuestoes.isEmpty()) {
            GerenciaBanco ger = new GerenciaBanco(bancoQuestoes);
            
            btnRemoverQuestao.setEnabled(true);
            btnAdicionarVersao.setEnabled(true);
            
            listaQuestoes.setListData(ger.getVetorQuestoes());
            listaQuestoes.setSelectedIndex(0);
            listaVersoes.setListData(ger.getVetorVersoes(0));
            
            if (listaQuestoes.getModel().getSize() > 0) { 
                listaVersoes.setSelectedIndex(0);
                btnRemoverQuestao.setEnabled(true);
                txtEnunciado.setText(bancoQuestoes.get(0).getQuestao(0).getEnunciado());

            }
        }
  }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        grupoCheckbox = new javax.swing.ButtonGroup();
        btnSalvar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listaVersoes = new javax.swing.JList();
        btnImportar = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        listaQuestoes = new javax.swing.JList();
        jLabel4 = new javax.swing.JLabel();
        btnAdicionarVersao = new javax.swing.JButton();
        btnRemoverVersao = new javax.swing.JButton();
        btnAdicionarQuestao = new javax.swing.JButton();
        btnRemoverQuestao = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        txtEnunciado = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Entradas e Gabaritos");

        btnSalvar.setText("Salvar Alterações");
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Lista (Entradas / Gabaritos)"));

        listaVersoes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listaVersoesMouseClicked(evt);
            }
        });
        listaVersoes.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listaVersoesValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(listaVersoes);

        btnImportar.setText("Importar banco");
        btnImportar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImportarActionPerformed(evt);
            }
        });

        jLabel2.setText("Questões");

        listaQuestoes.setModel(new javax.swing.AbstractListModel() {
            String[] strings = {" " };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listaQuestoes.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listaQuestoesValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(listaQuestoes);

        jLabel4.setText("Versões");

        btnAdicionarVersao.setText("Adicionar Versão");
        btnAdicionarVersao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdicionarVersaoActionPerformed(evt);
            }
        });

        btnRemoverVersao.setText("Remover Versão");
        btnRemoverVersao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoverVersaoActionPerformed(evt);
            }
        });

        btnAdicionarQuestao.setText("Adicionar Questão");
        btnAdicionarQuestao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdicionarQuestaoActionPerformed(evt);
            }
        });

        btnRemoverQuestao.setText("Remover Questão");
        btnRemoverQuestao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoverQuestaoActionPerformed(evt);
            }
        });

        jLabel6.setText("Enunciado");

        txtEnunciado.setColumns(20);
        txtEnunciado.setRows(5);
        jScrollPane5.setViewportView(txtEnunciado);

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel2)
                                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 96, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel4)
                                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(btnAdicionarQuestao, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                                    .add(btnRemoverQuestao, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                                    .add(btnAdicionarVersao, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                                    .add(btnRemoverVersao, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .add(btnImportar)
                                        .add(10, 10, 10))))
                            .add(jLabel6))
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(btnImportar)
                .add(29, 29, 29)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(jLabel4))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(btnAdicionarQuestao)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(btnRemoverQuestao)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(btnAdicionarVersao)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(btnRemoverVersao))
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel6)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 138, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, btnSalvar))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(btnSalvar)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        try {
            for(QuestaoProva questao: bancoQuestoes)
                if(questao.getArrayListQuestao().isEmpty())
                    throw new IOException();
            
            JFileChooser fc = new JFileChooser();
            File arqQuestao = null;

            UIManager.put("FileChooser.openDialogTitleText", "Salvar Banco");
            fc.setCurrentDirectory(new File(Estado.getInstancia().getDiretorio().getAbsolutePath()));
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            Janelas.alinharContainer(fc);
            fc.setSelectedFile(new File("BancoQuestoes.ser"));
            int resultado = fc.showSaveDialog(this);
            if(resultado == JFileChooser.CANCEL_OPTION){
                return;
            } else {
                arqQuestao = fc.getSelectedFile();
                if(!arqQuestao.getAbsolutePath().endsWith(".ser"))
                    arqQuestao = new File(arqQuestao.getAbsolutePath() + ".ser");
                if(arqQuestao.exists()){
                    int opcao = JOptionPane.showConfirmDialog(null, "Deseja sobreescrever?","Questão existente",JOptionPane.OK_CANCEL_OPTION);
                    if(opcao == JOptionPane.CANCEL_OPTION)
                        return;
                }
            }

            BancoQuestoes.setInstancia(bancoQuestoes);
            GerenciaSerializacao ger = new GerenciaSerializacao();
            ger.serializar(arqQuestao.getName());
            JOptionPane.showMessageDialog(null, 
                    "Altera��es salvas com sucesso!", 
                    "Sucesso!", 
                    JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
        } catch (IOException e) {
            JOptionPane.showMessageDialog(null, "Existe uma quest�o que n�o tem " +
                    "nenhum teste associado!\n Por favor adicione no m�nimo um teste!", 
                    "Questao sem teste", JOptionPane.ERROR_MESSAGE);
        } catch(IndexOutOfBoundsException e){
            e.printStackTrace();
        }
        
    }//GEN-LAST:event_btnSalvarActionPerformed
    
    private void btnImportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportarActionPerformed
        UIManager.put("FileChooser.openDialogTitleText", "Importar Banco de Quest�es...");
        File arquivo = null;
        
        File dirPadrao = Estado.getInstancia().getDiretorio();
        JFileChooser fc = new JFileChooser();
        if (dirPadrao != null) {
            fc.setCurrentDirectory(dirPadrao);
        }
        
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int resultado = fc.showOpenDialog(this);
        Janelas.alinharContainer(fc);
        if (resultado == JFileChooser.CANCEL_OPTION) {
            return;
        } else {
            arquivo = fc.getSelectedFile();
            try {
                GerenciaSerializacao gerSer = new GerenciaSerializacao();
                gerSer.desserializarBancoQuestoes(arquivo);
                bancoQuestoes = (ArrayList<QuestaoProva>)BancoQuestoes.getInstancia().getArrayListQuestaoProva().clone();
                iniciarListas();
                JOptionPane.showMessageDialog(this, "Importa��o Conclu�da!", "Conclu�do!",
                    JOptionPane.INFORMATION_MESSAGE);
                modificado = false;
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, "O arquivo informado n�o constitui " +
                        "um arquivo v�lido de quest�es para o Corretor!", "Arquivo Inv�lido!",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
}//GEN-LAST:event_btnImportarActionPerformed

    private void listaVersoesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listaVersoesMouseClicked
//        if (evt.getClickCount() > 1) {
//            int testeSelecionado = listaVersoes.getSelectedIndex();
//            Questao questao = questoes.get(listaProvas.getSelectedIndex());
//            TabelasTeste tab = new TabelasTeste(null, testeSelecionado, questao.getTeste(testeSelecionado));
//            tab.setVisible(true);
//            if (tab.getSaidaNormal()) {
//                questao.editarTeste(testeSelecionado, tab.getTeste());
//            }
//        }
}//GEN-LAST:event_listaVersoesMouseClicked

    private void listaQuestoesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listaQuestoesValueChanged
        int nroVersoes;
        
        if (listaQuestoes.getSelectedIndex() >= 0) {
            GerenciaBanco ger = new GerenciaBanco(bancoQuestoes);           

            listaVersoes.setListData(new String[0]);
            btnRemoverQuestao.setEnabled(true);
            btnAdicionarVersao.setEnabled(true);
            btnRemoverVersao.setEnabled(false);
            txtEnunciado.setText("");
            nroVersoes = bancoQuestoes.get(listaQuestoes.getSelectedIndex())
                    .getArrayListQuestao().size();
            if(nroVersoes > 0) {
                listaVersoes.setListData(ger.getVetorVersoes(
                        listaQuestoes.getSelectedIndex()));
                listaVersoes.setSelectedIndex(0);
                txtEnunciado.setText(bancoQuestoes
                    .get(listaQuestoes.getSelectedIndex()) 
                    .getQuestao(listaVersoes.getSelectedIndex())
                    .getEnunciado());
                btnRemoverVersao.setEnabled(true);
            }
            modificado = true;
        }
    }//GEN-LAST:event_listaQuestoesValueChanged

    private void listaVersoesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listaVersoesValueChanged
        if (listaVersoes.getSelectedIndex() >= 0) {
            txtEnunciado.setText(bancoQuestoes
                .get(listaQuestoes.getSelectedIndex()) 
                .get(listaVersoes.getSelectedIndex())
                .getEnunciado());
            modificado = true;
        }
    }//GEN-LAST:event_listaVersoesValueChanged

    private void btnAdicionarVersaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdicionarVersaoActionPerformed
        File dirPadrao = Estado.getInstancia().getDiretorio();
        JFileChooser fc = new JFileChooser();
        File arqQuestao = null;
        
        UIManager.put("FileChooser.openDialogTitleText", "Importar Quest\u00e3o");
        if(dirPadrao != null){
            fc.setCurrentDirectory(dirPadrao);
        } else {
            Estado.getInstancia().setDiretorio(new File(System.getProperty("user.dir")));
            dirPadrao = Estado.getInstancia().getDiretorio();
            fc.setCurrentDirectory(dirPadrao);
        }
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        Janelas.alinharContainer(fc);
        int resultado = fc.showOpenDialog(this);
        if(resultado == JFileChooser.CANCEL_OPTION){
            return;
        } else {
            arqQuestao = fc.getSelectedFile();
            Questao questao = null;
            try {
                GerenciaSerializacao gerSer = new GerenciaSerializacao();
                questao = gerSer.desserializarQuestao(arqQuestao);
                bancoQuestoes.get(listaQuestoes.getSelectedIndex())
                            .add(questao);
                GerenciaBanco ger = new GerenciaBanco((bancoQuestoes));
                int selectedIndex = listaVersoes.getSelectedIndex();
                listaVersoes.setListData(ger.getVetorVersoes(listaQuestoes.getSelectedIndex()));
                listaVersoes.clearSelection();
                listaVersoes.setSelectedIndex(++selectedIndex);
                btnRemoverVersao.setEnabled(true);
                modificado = true;
            } catch(IOException e){
                JOptionPane.showMessageDialog(this, "O arquivo informado n\u00e3o " +
                                "\u00e9 v\u00e1lido .ser!", "Arquivo Inv\u00e1lido!",
                                JOptionPane.ERROR_MESSAGE);
            } catch(IndexOutOfBoundsException e) {
                e.printStackTrace();
            }
        }
}//GEN-LAST:event_btnAdicionarVersaoActionPerformed

    private void btnRemoverVersaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoverVersaoActionPerformed
        if(listaVersoes.getSelectedIndex() >= 0){
            bancoQuestoes.get(listaQuestoes.getSelectedIndex())
                       .removerQuestao(listaVersoes.getSelectedIndex());

            GerenciaBanco ger = new GerenciaBanco(bancoQuestoes);
            listaVersoes.setListData(ger.getVetorVersoes(listaQuestoes.getSelectedIndex()));
            btnRemoverVersao.setEnabled(false);
            txtEnunciado.setText("");
            
            if(listaVersoes.getModel().getSize() > 0){
                btnRemoverVersao.setEnabled(true);
                listaVersoes.setSelectedIndex(0);
                txtEnunciado.setText(bancoQuestoes
                        .get(listaQuestoes.getSelectedIndex())
                        .getQuestao(0)
                        .getEnunciado());
            }
             modificado = true;       
        }

}//GEN-LAST:event_btnRemoverVersaoActionPerformed

    private void btnAdicionarQuestaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdicionarQuestaoActionPerformed
       bancoQuestoes.add(new QuestaoProva());
       
       GerenciaBanco ger = new GerenciaBanco(bancoQuestoes);
       listaQuestoes.setListData(ger.getVetorQuestoes());
       listaQuestoes.setSelectedIndex(listaQuestoes.getLastVisibleIndex());
       listaVersoes.setListData(ger.getVetorVersoes(listaQuestoes.getSelectedIndex()));
       btnRemoverQuestao.setEnabled(true);
       btnAdicionarVersao.setEnabled(true);
       txtEnunciado.setText("");
       modificado = true;
}//GEN-LAST:event_btnAdicionarQuestaoActionPerformed

    private void btnRemoverQuestaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoverQuestaoActionPerformed
        bancoQuestoes.remove(listaQuestoes.getSelectedIndex());
        
        GerenciaBanco ger = new GerenciaBanco(bancoQuestoes);
        listaQuestoes.setListData(ger.getVetorQuestoes());
        listaVersoes.setListData(new String[0]);
        btnRemoverQuestao.setEnabled(false);
        btnAdicionarVersao.setEnabled(false);
        btnRemoverVersao.setEnabled(false);
        txtEnunciado.setText("");
        if(listaQuestoes.getModel().getSize() > 0 ){
            listaQuestoes.setSelectedIndex(0);
            listaVersoes.setListData(ger.getVetorVersoes(0));
            btnRemoverQuestao.setEnabled(true);
            btnAdicionarVersao.setEnabled(true);
            if(listaQuestoes.getModel().getSize() > 0){
                listaVersoes.setSelectedIndex(0);
                btnRemoverVersao.setEnabled(true);
                txtEnunciado.setText(bancoQuestoes
                        .get(listaQuestoes.getSelectedIndex())
                        .getQuestao(0)
                        .getEnunciado());
            }
        }
        modificado = true;
}//GEN-LAST:event_btnRemoverQuestaoActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdicionarQuestao;
    private javax.swing.JButton btnAdicionarVersao;
    private javax.swing.JButton btnImportar;
    private javax.swing.JButton btnRemoverQuestao;
    private javax.swing.JButton btnRemoverVersao;
    private javax.swing.JButton btnSalvar;
    private javax.swing.ButtonGroup grupoCheckbox;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JList listaQuestoes;
    private javax.swing.JList listaVersoes;
    private javax.swing.JTextArea txtEnunciado;
    // End of variables declaration//GEN-END:variables
    
}
